package com.anche.cywebnew.Utils.HikUtil;

import com.anche.cywebnew.DTO.HikBaseDTO;
import com.sun.jna.NativeLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.MessageFormat;

/**
 * 海康设备拍照
 */
public class CaptureUtil extends CommonUtil {

    private static final Logger logger = LoggerFactory.getLogger(CaptureUtil.class);

    private HCNetSDK.NET_DVR_JPEGPARA jpegpara;

    public CaptureUtil() {
        HCNetSDK.NET_DVR_JPEGPARA jpegpara = new HCNetSDK.NET_DVR_JPEGPARA();
        jpegpara.wPicSize = 0xff;
        jpegpara.wPicQuality = 0;
        this.jpegpara = jpegpara;
    }

    public CaptureUtil(HCNetSDK.NET_DVR_JPEGPARA jpegpara) {
        this.jpegpara = jpegpara;
    }

    public boolean doCapture(NativeLong lUserID, NativeLong ch, String fileName) {
        boolean capture = hCNetSDK.NET_DVR_CaptureJPEGPicture(lUserID, ch, jpegpara, fileName);
        if (capture) {
            logger.info("抓图成功");
        } else {
            int code = hCNetSDK.NET_DVR_GetLastError();
            String msg = HikErrorUtil.getMsgByCode(code);
            resultMsg = String.format(errMsg, "抓图失败", code, msg);
            logger.info("抓图失败：错误码[{}]，错误描述[{}]", code, msg);
        }
        return capture;
    }
}
